package com.itqian.seller.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itqian.seller.entity.FoodCategory;
import com.itqian.seller.mapper.FoodCategoryMapper;
import com.itqian.seller.service.FoodCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itqian.seller.vo.FoodCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 菜品类别表 服务实现类
 * </p>
 *
 * @author shishuqian
 * @since 2022-03-21
 */
@Service
public class FoodCategoryServiceImpl extends ServiceImpl<FoodCategoryMapper, FoodCategory> implements FoodCategoryService {

    @Autowired
    private FoodCategoryMapper foodCategoryMapper;

    @Override
    public List<FoodCategoryVO> findAllCategoryVO(Integer storeId) {
        //根据店铺id查询所有菜品分类
        QueryWrapper<FoodCategory> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",storeId);
        List<FoodCategory> foodCategories = foodCategoryMapper.selectList(wrapper);
        //转换数据格式返回
        List<FoodCategoryVO> list = new ArrayList<>();
        for (FoodCategory foodCategory : foodCategories) {
            FoodCategoryVO vo = new FoodCategoryVO();
            BeanUtils.copyProperties(foodCategory,vo);
            list.add(vo);
        }
        return list;
    }

}
